home *** CD-ROM | disk | FTP | other *** search
- ******************************************************************
- * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
- * - Note: This is a real, live, actual, registered copyright,
- * and should be treated as such. This source code is from
- * the book "68000 Assembly Language", Krantz and Stanley,
- * Addison-Wesley Publishing Company, Reading, MA, 1986.
- *
- * Permission granted by the authors for non-commercial use
- * in programs released to the public domain, as long as this
- * copyright notice remains attached and visible.
- *
- *****************************************************************
- * EDIT1 - Editor file I/O routines.
- *
- * Routines: READ_IN Reads a file into an editing buffer.
- * Entry: Register A5.L points to an initialized
- * edit buffer descriptor block.
- * Register A0.L points to filename string
- * Exit: ed_err(a5) set if any problems.
- *
- * WRITE_OUT writes a block of memory data to a
- * file.
- * Entry: Register A0.L points to filename string.
- * Register A1.L points to the start of data
- * area in memory. D1.W holds number of
- * bytes to write into file.
- * Exit: ed_err(a5) set if any problems.
-
- .xref open,close,fgetc,fputc
- .xdef read_in,write_out
-
- #fcb.h
- #edit.h
-
- *****************************************************************
- * READ_IN - Reads a file into an editing buffer.
- read_in:
- movem.l d1/a0/a1,-(a7) * Save caller's registers.
- link a6,#-file * Create an FCB on the stack
- move.l a7,a1 * get FCB address
- move.w #0,-(a7) * Push 0 for "File Must Exist"
- move.l a0,-(a7) * Push filename
- move.l a1,-(a7) * Push FCB address
- bsr open * Attempt open
- tst.w d0 * Did it work?
- bpl sk1_read * Yes.
- move.w #1,d0 * Show "File-not-found" error
- bra read_exit * Say goodbye.
- sk1_read:
- move.l e_gap(a5),d1 * Compute buffer length
- sub.l b_gap(a5),d1
- move.l b_gap(a5),a1 * Setup pointer to data area
- bra sk3_read * Loop test done before read
- lp1_read:
- bsr fgetc * Read character
- tst.w d0 * Look for end of file
- bmi sk2_read * Yes, found end-of-file
- cmp.b #13,d0 * is this C/R?
- beq lp1_read * yes, just skip it.
- move.b d0,(a1)+ * Store datum
- sk3_read:
- dbra d1,lp1_read * Go for the next one.
- move.w #2,d0 * If we're here, file's too big.
- bra read_exit * So leave.
- sk2_read:
- move.l a1,b_gap(a5) * save in descriptor structure
- move.w #0,d0 * Show successful read.
- read_exit:
- unlk a6 * Restore frame pointer
- movem.l (a7)+,d1/a0/a1 * Restore caller's registers.
- rts
- *****************************************************************
- * WRITE_OUT - writes a file to disk
- write_out:
- movem.l d1/a0-a2,-(a7) * Save caller's registers.
- link a6,#-file * Create an FCB on the stack
- move.l a7,a2 * Get FCB address
- move.w #$FFFF,-(a7) * Push -1 for "Create File"
- move.l a0,-(a7) * Push filename
- move.l a2,-(a7) * Push FCB address
- bsr open * Attempt open
- tst.w d0 * Did it work?
- bpl sk4_write * Yes, loop test before write.
- move.w #1,d0 * Show "Can't make file" error
- bra write_exit * Say goodbye.
- lp1_write:
- cmp.b #10,(a1) * Is this a newline?
- bne sk3_write * No.
- move.b #13,5(a7) * Store RETURN into stack
- bsr fputc * write RETURN.
- tst.w d0 * Look for error.
- bmi sk2_write * Yes, found error.
- sk3_write:
- move.b (a1)+,5(a7) * Store parameter into stack
- bsr fputc * write character
- tst.w d0 * Look for error.
- bmi sk2_write * Yes, found error.
- sk4_write:
- dbra d1,lp1_write * Go for the next one.
- move.l a2,-(a7) * push FCB address
- bsr close * close file
- tst.w d0 * smooth return code
- bmi write_exit * error exit
- clr.w d0 * show success
- bra write_exit * and get out of here.
- sk2_write:
- move.w #1,d0 * Show error.
- write_exit:
- unlk a6 * Restore frame pointer
- movem.l (a7)+,d1/a0-a2 * Restore caller's registers.
- rts
-
- end